
var CodeDept='';
function showImg($top,$left,$posy,$height,$codeDepartement){
	CodeDept=$codeDepartement;
	$('#carteVol').hide();
	$('#carteVol').css({
		top: $top+'px',
		left: $left+'px',
		backgroundPosition:'0px '+$posy+'px',
		height: $height+'px'
	});
	$('#carteVol').show();
	$('#ensemble').show();
}
function getCodeDept(){
	regionId = new Array('67,68',
			'24,33,40,47,64',
			'03,15,43,63',
			'14,50,61',
			'21,58,71,89',
			'22,29,35,56',
			'18,28,36,37,41,45',
			'08,10,51,52',
			'2A,2B',
			'25,39,70,90',
			'27,76',
			'75,77,78,91,92,93,94,95',
			'11,30,34,48,66',
			'19,23,87',
			'54,55,57,88',
			'09,12,31,32,46,65,81,82',
			'59,62',
			'44,49,53,72,85',
			'02,60,80',
			'16,17,79,86',
			'04,05,06,13,83,84',
			'01,07,26,38,42,69,73,74',
			'971,972,973,974,975,976',
			'984,986,987,988'
	);
	getRegion='';
	for(i=0;i<regionId.length;i++){
		
		if(regionId[i].indexOf(CodeDept)>=0){
			 getRegion=regionId[i];
			 $('#region option:selected', this).remove();
			 $('#region').val(getRegion);
			 break;
		}
	}
	if(getRegion!=''){
		 showLocalisation('departement',getRegion);
		 $('#departement').val(CodeDept);
	}
	if(getRegion!='') showLocalisation('ville',CodeDept);
	$('#cp').val( CodeDept);
	$('#ensemble').hide('slow');
}





//----------------------------------------------------------------------
function convert_accent(_string){
	var nomarkKeyA=new RegExp('[Ă,Â,Á,À,Ả,Ã,Ạ,Ắ,Ằ,Ẳ,Ẵ,Ặ,Ấ,Ầ,Ẩ,Ẫ,Ậ]','g');
	var nomarkKeya=new RegExp('[ă,â,á,à,ả,ã,ạ,ắ,ằ,ẳ,ẵ,ặ,ấ,ầ,ẩ,ẫ,ậ,ä]','g');
	var nomarkKeyE=new RegExp('[Ê,É,È,Ẻ,Ẽ,Ẹ,Ế,Ề,Ể,Ễ,Ệ]','g');
	var nomarkKeye=new RegExp('[ê,é,è,ẻ,ẽ,ẹ,ế,ề,ể,ễ,ệ,ë]','g');
	var nomarkKeyO=new RegExp('[Ô,Ơ,Ó,Ò,Ỏ,Õ,Ọ,Ố,Ồ,Ổ,Ỗ,Ộ,Ớ,Ờ,Ở,Ỡ,Ợ]','g');
	var nomarkKeyo=new RegExp('[ô,ơ,ó,ò,ỏ,õ,ọ,ố,ồ,ổ,ỗ,ộ,ớ,ờ,ở,ỡ,ợ,ö]','g');
	var nomarkKeyU=new RegExp('[Ư,Ú,Ù,Ủ,Ũ,Ụ,Ứ,Ừ,Ử,Ữ,Ự]','g');
	var nomarkKeyu=new RegExp('[ư,ú,ù,ủ,ũ,ụ,ứ,ừ,ử,ữ,ự,ü]','g');
	var nomarkKeyI=new RegExp('[Í,Ì,Ỉ,Ĩ,Ị]','g');
	var nomarkKeyi=new RegExp('[í,ì,ỉ,ĩ,ị,ï,î]','g');
	var nomarkKeyY=new RegExp('[Ý,Ỳ,Ỷ,Ỹ,Ỵ]','g');
	var nomarkKeyy=new RegExp('[ý,ỳ,ỷ,ỹ,ỵ,ÿ]','g');
	var nomarkKeyc=new RegExp('[ç]','g');
	var nomarkKeyC=new RegExp('[Ç]','g');
	var nomarkKeyD=new RegExp('[Đ]','g');
	var nomarkKeyd=new RegExp('[đ]','g');
	var nomarkKeyOther=new RegExp('[!-/,:,\[-^,`,{-~]','g');
	_string=$.trim(_string);
	_string=_string.replace(nomarkKeyOther,' ');
	_string=_string.replace(/\s+/g," ");
	_string=_string.replace(/ /g,'-');
	_string=_string.replace(nomarkKeyA,'A');
	_string=_string.replace(nomarkKeya,'a');
	_string=_string.replace(nomarkKeyE,'E');
	_string=_string.replace(nomarkKeye,'e');
	_string=_string.replace(nomarkKeyO,'O');
	_string=_string.replace(nomarkKeyo,'o');
	_string=_string.replace(nomarkKeyU,'U');
	_string=_string.replace(nomarkKeyu,'u');
	_string=_string.replace(nomarkKeyI,'I');
	_string=_string.replace(nomarkKeyi,'i');
	_string=_string.replace(nomarkKeyY,'Y');
	_string=_string.replace(nomarkKeyy,'y');
	_string=_string.replace(nomarkKeyc,'c');
	_string=_string.replace(nomarkKeyC,'C');
	_string=_string.replace(nomarkKeyD,'D');
	_string=_string.replace(nomarkKeyd,'d');
	checkUrl(_string);
	return _string;
} 
function checkUrl(url_friendly){
	$.post("admin/checkURL", { url: url_friendly})
	.done(function(data) {
		$('#ajax-response').html(data);
	});
} 
$(document).ready(function() {


    $('.checkall').click(function () {
        $(this).closest('table').find(':checkbox').prop('checked', this.checked);
    });
	 $(".editinline").click(function () {
		 selectorInfo=$(this).parents('div.row-actions').next();
			$id=selectorInfo.attr('id').replace('inline_', "");
			$name=selectorInfo.find(".name").text();
			$slug=selectorInfo.find(".slug").text();
			$parent=selectorInfo.find(".parent").text();
			$('#inlineedit').insertAfter($(this).parents('tr'));
			selectorNewTr=$(this).parents('tr').next();
			selectorNewTr.find('input[name="name"]').val($name);
			selectorNewTr.find('input[name="slug"]').val($slug);
			selectorNewTr.find('input[name="id"]').val($id);
			selectorNewTr.find('input[name="parent"]').val($parent);
			$('.inline-edit-row').show();
			$(this).parents('tr').hide();
		 });

	 $(".editinlineOption").click(function(){
		 selectorInfo=$(this).parents('div.row-actions').next();
		 $id=selectorInfo.attr('id').replace('inline_', "");
		 $name=selectorInfo.find(".name").text();
		 $type=selectorInfo.find(".type").text();
		 $value=selectorInfo.find(".value").text();
		 $('#inlineedit').insertAfter($(this).parents('tr'));
		 selectorNewTr=$(this).parents('tr').next();
		 selectorNewTr.find('input[name="name"]').val($name);
		 selectorNewTr.find('select[name="type"]').val($type);
		 selectorNewTr.find('input[name="id"]').val($id);
		 selectorNewTr.find('textarea[name="value"]').val($value);
		 $('.inline-edit-row').show();
		 $(this).parents('tr').hide();
	 });
	 $(".editinlineAdminMenu").click(function(){
		 selectorInfo=$(this).parents('div.row-actions').next();
		 $id=selectorInfo.attr('id').replace('inline_', "");
		 $name=selectorInfo.find(".name").text();
		 $type=selectorInfo.find(".parent").text();
		 $href=selectorInfo.find(".href").text();
		 $class=selectorInfo.find(".class").text();
		 $icon=selectorInfo.find(".icon").text();
		 $('#inlineedit').insertAfter($(this).parents('tr'));
		 selectorNewTr=$(this).parents('tr').next();
		 selectorNewTr.find('input[name="name"]').val($name);
		 selectorNewTr.find('select[name="parent"]').val($type);
		 selectorNewTr.find('input[name="id"]').val($id);
		 selectorNewTr.find('input[name="class"]').val($class);
		 selectorNewTr.find('input[name="href"]').val($href);
		 selectorNewTr.find('input[name="icon"]').val($icon);
		 $('.inline-edit-row').show();
		 $(this).parents('tr').hide();
	 });
	 $(".delPhoto").click(function(){
		 $id=$(this).attr('id');
		 $(this).prev().animate({ opacity: 0.3 }, 800);
		 $('<input type="hidden" name="delPhoto[]" value="'+$id+'" />').insertAfter($(this));
		 $(this).remove();
	 }); 
});


function autoTag($divInput){
	var word=$('#title').val().replace(/[^a-zA-Z0-9ãàáäâẽèéëêìíïîõòóöôùúüûñç,.]+/g,' ').split(' ');
	//word=$.unique(word); 
	var uniqueArr = [];
		for (var i = word.length; i--; ) {
            var val = word[i];
            if ($.inArray(val, uniqueArr) === -1) {
                uniqueArr.unshift(val);
            }
        }
	$('#'+$divInput).val(uniqueArr.join(','));
}